package org.example.consumer.service;

import org.apache.seata.spring.annotation.GlobalTransactional;
import org.example.consumer.client.OrderFeign;
import org.example.consumer.client.StockFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class BusinessService {
    @Autowired
    private OrderFeign orderFeign;
    @Autowired
    private StockFeign stockFeign;

    @GlobalTransactional(rollbackFor = Exception.class)
    public void purchase(String userId, String commodityCode, int count, int money){
        orderFeign.create(userId, commodityCode, count, money);
        stockFeign.deduct(commodityCode, count);
        if(count==99){
            throw new RuntimeException("fail");
        }
    }
}